package com.wh.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class AspectDemo {
    @Around("@annotation(com.wh.aop.config.MyAspect)")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        //记录⽅法执⾏开始时间
        long start = System.currentTimeMillis();
        //执⾏原始⽅法
        Object result = joinPoint.proceed();
        //记录⽅法执⾏结束时间
        long end = System.currentTimeMillis();
        //记录⽅法执⾏耗时
        log.info(joinPoint.getSignature() + "执⾏耗时: {}ms", end - start);
        return result;
    }
}
